﻿using System.Collections.Generic;
using BaiduEditor.PluginInterface;

using FirstPlugin.UI;

namespace FirstPlugin
{
	public class TestPlugin:PluginBase
	{
		public void Initialize()
		{

		}

		public override List<Operation> GetOperations()
		{
			List<Operation> result = new List<Operation>();

			Operation op = new Operation("所有信息", onAllInfoOperate, null);
			Operation op1 = new Operation("帐户", onAccountOperate, null);
			Operation op2 = new Operation("Hi", onAccountOperate, onGetState);
			Operation op3 = new Operation("推广计划", onCampaignsOperate, null);
			Operation op4 = new Operation("推广单元", onAdGroupsOperate, null);

			result.Add(op);
			result.Add(op1);
			result.Add(op2);
			result.Add(op3);
			result.Add(op4);
			return result;
		}

		public override PluginResult MessageProc(PluginMessage msg)
		{
			return null;
		}

		public override void NotificationProc(PluginNotification notification)
		{
			throw new System.NotImplementedException();
		}


		private void onAllInfoOperate()
		{
			MainForm form = new MainForm(loader);
			//form.ShowDialog();
			form.Show();
		}

		private void onAccountOperate()
		{
			PluginGetParameter getParam = new PluginGetParameter(null);
			PluginMessage getMsg = new PluginMessage(PluginMessageCode.GetCurrentAccount, getParam);
			PluginResult result = loader.CallEditor(getMsg);
			AccountForm form = new AccountForm(result);
			form.ShowDialog();
		}

		private void onCampaignsOperate()
		{
			PluginGetParameter getParam = new PluginGetParameter(null);
			PluginMessage getMsg = new PluginMessage(PluginMessageCode.GetCampaigns, getParam);
			PluginResult result = loader.CallEditor(getMsg);
			CampaignsForm form = new CampaignsForm(result);
			form.ShowDialog();
		}

		private void onAdGroupsOperate()
		{
			PluginGetParameter getParam = new PluginGetParameter(null);
			PluginMessage getMsg = new PluginMessage(PluginMessageCode.GetAdGroups, getParam);
			PluginResult result = loader.CallEditor(getMsg);
			AdGroupsForm form = new AdGroupsForm(result);
			form.ShowDialog();
		}

		public PluginOperationState onGetState()
		{
			return PluginOperationState.Disabled;
		}
	}
}
